<?php
/**
 * TomatoCMS
 *
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@tomatocms.com so we can send you a copy immediately.
 *
 * @copyright    Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license        http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version     $Id: add.phtml 3032 2010-05-25 08:00:42Z huuphuoc $
 */
?>
<?php
$this->headTitle($this->translator('product_edit_page_title'));
$this->headScript()
    ->appendFile($this->APP_STATIC_SERVER . '/js/jquery.validate/jquery.validate.min.js')
    ->appendFile($this->APP_STATIC_SERVER . '/js/tomato/util.js');
	
?>
<script type="text/javascript" src="<?php echo $this->APP_STATIC_SERVER; ?>/js/tinymce/tiny_mce.js"></script>
<style>
    .box_image{
        position:relative; float:left; width:160px; padding-top:5px;
    }
    .box_image a{
        left:133px; top:2px; position:absolute; color:
    }
</style>
<div class="grid_12 t_a_ui_breadcrumb">
    <span><a href="<?php echo $this->url(array(), 'shop_product_list'); ?>"><?php echo $this->translator('product_list_breadcump'); ?></a></span>
    <span><?php echo $this->translator('product_edit_breadcump'); ?></span>
</div>

<div class="grid_12"><?php echo $this->flashMessenger(); ?></div>
<?php $product = $this->product;?>
<form method="post" action="<?php echo $this->url(array(), 'shop_product_edit'); ?>" id="editProductForm">
<div>&nbsp;</div>
<div class="grid_12 t_a_bottom" style="font-size:13px; font-weight:bold">1. <?php echo $this->translator('product_basic_guide'); ?></div>
<div class="grid_12"><hr /></div>

<?php if(!$this->isAllowed):?>
<div class="grid_12"><?php echo $this->translator('product_not_edit_basic_guide'); ?></div>
<?php else:?>
<div class="grid_12 t_a_bottom">
    <div class="prefix_1 suffix_1">
        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('product_admin_name'); ?>:</label>
            <input type="text" id="product_admin_name" name="product_admin_name" value="<?php echo $product->product_admin_name;?>" style="width: 300px" />
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('product_status'); ?>:</label>
            <select id="product_status" name="product_status" style="width:170px">
                <option value="">---</option>
                <option value="1" <?php if($product->product_status == 1){ echo "selected"; }?>><?php echo $this->translator('product_status_active'); ?></option>
                <option value="0" <?php if($product->product_status == 0){ echo "selected"; }?>><?php echo $this->translator('product_status_inactive'); ?></option>
            </select>
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('product_price'); ?>:</label>
            <input type="text" id="product_price" name="product_price" value="<?php echo $product->product_price;?>" style="width: 170px" /> <?php echo isset($product->product_price_currency)?$product->product_price_currency:null;?>
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('product_status_of_delivery'); ?>:</label>
            <select id="product_status_of_delivery" name="product_status_of_delivery" style="width:170px">
                <option value="">---</option>
                <option value="deliver_able" <?php if($product->product_status_of_delivery == 'deliver_able'){echo 'selected';}?>><?php echo $this->translator('product_status_of_delivery_deliverable'); ?></option>
                <option value="non_deliver_able" <?php if($product->product_status_of_delivery == 'non_deliver_able'){echo 'selected';}?>><?php echo $this->translator('product_status_of_delivery_non_deliverable'); ?></option>
                <option value="please_contact" <?php if($product->product_status_of_delivery == 'please_contact'){echo 'selected';}?>><?php echo $this->translator('product_status_of_delivery_please_contact'); ?></option>
            </select>
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('product_quantity_mode'); ?>:</label>
            <select id="product_quantity_mode" name="product_quantity_mode" style="width:170px" <?php if($product->product_quantity_mode == ''){echo 'disabled';}?>>
                <option value="">---</option>
                <option value="infinity" <?php if($product->product_quantity_mode == 'infinity'){echo 'selected';}?>><?php echo $this->translator('product_quantity_mode_infinity'); ?></option>
                <option value="amount" <?php if($product->product_quantity_mode == 'amount'){echo 'selected';}?>><?php echo $this->translator('product_quantity_mode_amount'); ?></option>
            </select>
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('product_quantity'); ?>:</label>
            <input type="text" <?php if($product->product_quantity == ''){echo 'disabled';}?> id="product_quantity" name="product_quantity" value="<?php echo $product->product_quantity;?>" style="width: 170px" />
        </div>

        <hr/>
		<!-- 
			Name   : Cong Ngo , date time : 9:59 - 26/4/2011
			purpose: chỉnh thêm button upload vào khi click vào upload sẽ hiển thị lên phần upload nếu không thì ẩn vùng đó đi
			content edit: CONG 1, CONG 2				
		
		<script language="javascript">	
			$(document).ready(function(){
				$("#btnUploadImage").click(function(){
					$("#divUploadImageArea").toggle();
				});
			});
		</script>
		
		-->
		
        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('product_image'); ?>:</label>
			<div class="clearfix" id="uploadFile">
				<?php
					echo $this->helperLoader('upload')->uploader('multimedia',
						array('extension' => '*.jpg;*.jpeg;*.png;*.gif', 'multi' => true, 'auto' => true, 'simUploadLimit' => 5,'sizeLimit' => 1024 * 1024 * 5),
						array('onProgress' => 'onUploadProgress', 'onComplete' => 'onUploadComplete'),
						'uploadFiles');					
				?>
				<div style="padding-left: 160px;">
					<?php 
						//.'/'.date('Y').'/'.date('m')
						echo $this->browser('/upload/multimedia/'.Zend_Auth::getInstance()->getIdentity()->user_name, 'jpg,gif,png', 'insertImage(%s)');
					?>
				</div>
				<div id="viewIMG" style="padding-left:160px"></div>
				<input type="hidden" id="product_image" name="product_image" value="<?php echo $product->product_image;?>" />
				<input type="hidden" value="1" id="hd_num_image" />				
			</div>
			<script language="javascript">
				function onUploadComplete(event, ID, fileObj, response, data) {
				};			
			</script>
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('product_created_date'); ?>:</label>
            <?php $date  = strtotime($product->product_created_date); echo date('d/m/Y', $date)?>
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('product_modified_date'); ?>:</label>
            <?php echo $this->date;?>
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('product_category'); ?>:</label>
            <select name="category_id[]" id="category_id[]" style="width:170px;">
                <option value="">---</option>
                <?php for ($i = 0; $i < count($this->categories); $i++) : ?>
                <option <?php if(strstr($product->category_id,",{$this->categories[$i]->category_id},")):?> selected <?php endif;?> value="<?php echo $this->categories[$i]->category_id; ?>"><?php echo str_repeat('---', $this->categories[$i]->depth).$this->categories[$i]->category_admin_name; ?></option>
            <?php endfor; ?>
            </select>
            <?php /*<div style="border:1px solid #CCC; padding: 5px; width:300px;overflow:auto;height:120px">
                <?php for ($i = 0; $i < count($this->categories); $i++) : ?>
                <input type="checkbox" <?php if(strstr($product->category_id,",{$this->categories[$i]->category_id},")){echo 'checked';}?> id="category_id[]" name="category_id[]" value="<?php echo $this->categories[$i]->category_id; ?>" <?php if($this->categories[$i]->category_enable_product != 1):?>disabled <?php endif;?> > <?php echo str_repeat('---', $this->categories[$i]->depth).$this->categories[$i]->category_admin_name; ?><br>
                <?php endfor; ?>
            </div>*/?>
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('product_bundle'); ?>:</label>
            <input type="radio" class="product_bundle" name="product_bundle" value="1" <?php if($product->product_bundle == 1){?>checked="checked"<?php }?>> Yes
            <input type="radio" class="product_bundle" name="product_bundle" value="0" <?php if($product->product_bundle == 0){?>checked="checked"<?php }?>> No<br />
            <div id="html_products" class="clearfix t_a_bottom" style="margin-left:20%;"> 
            </div>
        </div>

        <hr/>

        <div class="clearfix t_a_bottom" <?php if($product->product_bundle == 1):?>style="display:none"<?php endif;?> >
            <label><?php echo $this->translator('product_shipping_price_1'); ?>:</label>
            <input type="text" name="product_shipping_price" id="product_shipping_price" value="<?php echo $product->product_shipping_price;?>"> <?php echo isset($this->enterprise->currency)?$this->enterprise->currency:null;?>
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('product_shipping_price'); ?>:</label>
            <input type="text" name="product_shipping_price_1" id="product_shipping_price_1" style="width:50px;" value="<?php echo $product->product_shipping_price_1;?>"> +
            <span><?php echo $this->translator('product_quantity');?></span> x
            <input type="text" name="product_shipping_price_2" id="product_shipping_price_2" style="width:50px;" value="<?php echo $product->product_shipping_price_2;?>">
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label>&nbsp;</label>
            <button type="submit"><span><?php echo $this->translator('product_add_save_button'); ?></span></button>&nbsp;&nbsp;&nbsp;
            <button type="reset"><span><?php echo $this->translator('product_reset_button'); ?></span></button>
        </div>
    </div>
</div>
</form>

<div class="grid_12 t_a_bottom" style="font-size:13px; font-weight:bold">2. <?php echo $this->translator('product_content_guide'); ?></div>
<?php $arrProductByLanguage = $this->arrProductByLanguage?>
<div class="grid_12"><hr></hr></div>
<?php foreach ($this->languages as $row):?>
<?php if($row->language_code == 'vi_VN'):?>
<!--language default content-->
<form method="post" action="<?php echo $this->url(array('product_id' => $this->product->product_id), 'shop_product_save_content'); ?>" id="addProductLanguageForm_<?php echo $row->language_code;?>" >
<div class="grid_12 t_a_bottom">
    <div class="prefix_1 suffix_1">
        <input type="hidden" id="product_content_id" name="product_content_id" value="<?php echo @$arrProductByLanguage[$row->language_code]->product_content_id?>" />
        <div class="clearfix t_a_bottom">
            <?php echo $this->translator('product_language_guide'); ?> <strong><?php echo $row->language_name;?></strong>
            <input type="hidden" id="language_code" name="language_code" value="<?php echo $row->language_code;?>" />
        </div>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('product_name'); ?>:</label>
            <input type="text" id="product_content_name" name="product_content_name" value="<?php echo @$arrProductByLanguage[$row->language_code]->product_content_name?>"  style="width: 300px" />
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('product_friendly_url'); ?>:</label>
            <input type="text" id="product_content_friendly_url" name="product_content_friendly_url" value="<?php echo @$arrProductByLanguage[$row->language_code]->product_content_friendly_url?>"  style="width: 300px" />
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('product_description'); ?>:</label>
            <textarea id="product_content_description_<?php echo $row->language_code?>" name="product_content_description" class="tinymce" style="width: 440px; height: 200px"><?php echo @$arrProductByLanguage[$row->language_code]->product_content_description;?></textarea>
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label>&nbsp;</label>
            <button type="submit"><span><?php echo $this->translator('product_add_save_button'); ?></span></button>&nbsp;&nbsp;&nbsp;
            <!--<button type="reset"><span><?php echo $this->translator('product_reset_button'); ?></span></button>-->
            <input type="checkbox" <?php if(@$arrProductByLanguage['en_US']->product_content_name == ''):?>disabled<?php endif;?> name="auto_translate" <?php if(!@$arrProductByLanguage['en_US']->product_content_id):?>checked<?php endif;?> />&nbsp;<?php echo $this->translator('product_edit_auto_translate');?>
            <input type="hidden" value="<?php echo @$arrProductByLanguage['en_US']->product_content_id;?>" name="product_content_id_en" />
        </div>
    </div>
</div>
<script type="text/javascript">
/**
 * Init TinyMCE instances
 */
tinyMCE.init({
    theme: 'advanced',
    theme_advanced_toolbar_location: 'top',
    theme_advanced_toolbar_align: 'left',
    width: '440',
    height: '225',
    mode: 'exact',
    elements: 'product_content_description_<?php echo $row->language_code?>',
    content_css: '<?php echo $this->APP_STATIC_SERVER; ?>/skins/<?php echo $this->APP_TEMPLATE; ?>/<?php echo $this->APP_SKIN; ?>/default.css',
    relative_urls: false,
    remove_script_host: false
})
</script>
</form>
<?php else:?>
<form method="post" action="<?php echo $this->url(array('product_id' => $this->product->product_id), 'shop_product_save_content'); ?>" id="addProductLanguageForm_<?php echo $row->language_code;?>" name="addProductLanguageForm_<?php echo $row->language_code;?>">
<div class="grid_12 t_a_bottom">
    <div class="prefix_1 suffix_1">
        <input type="hidden" id="product_content_id" name="product_content_id" value="<?php echo @$arrProductByLanguage[$row->language_code]->product_content_id;?>" />
        <div class="clearfix t_a_bottom">
            <?php echo $this->translator('product_language_guide'); ?> <strong><?php echo $row->language_name;?></strong>
            <input type="hidden" id="language_code" name="language_code" value="<?php echo $row->language_code;?>" />
        </div>

        <?php if(@$arrProductByLanguage[$row->language_code]->product_content_id != null):?>
        <!--<div class="clearfix">
            <label>&nbsp;</label>
            <input type="checkbox" name="edit_content" id="edit_content_<?php echo $row->language_code;?>" />&nbsp;<?php echo $this->translator('product_to_edit_content');?>
        </div>
        <hr/>-->
        <?php endif;?>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('product_name'); ?>:</label>
            <input type="text" id="product_content_name" name="product_content_name" value="<?php echo @$arrProductByLanguage[$row->language_code]->product_content_name?>"  style="width: 300px" />
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('product_friendly_url'); ?>:</label>
            <input type="text" id="product_content_friendly_url" name="product_content_friendly_url" value="<?php echo @$arrProductByLanguage[$row->language_code]->product_content_friendly_url?>"  style="width: 300px" />
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label><?php echo $this->translator('product_description'); ?>:</label>
            <textarea id="product_content_description_<?php echo $row->language_code?>" name="product_content_description" class="tinymce" style="width: 440px; height: 200px"><?php echo @$arrProductByLanguage[$row->language_code]->product_content_description;?></textarea>
        </div>

        <hr/>

        <div class="clearfix t_a_bottom">
            <label>&nbsp;</label>
            <button type="submit"><span><?php echo $this->translator('product_add_save_button'); ?></span></button>&nbsp;&nbsp;&nbsp;
        </div>
    </div>
</div>
<script type="text/javascript">

</script>
</form>
<script type="text/javascript">
<?php if (@$arrProductByLanguage[$row->language_code]->product_content_name == ''): ?>
window.onload= function(){
    disableEnableForm(document.addProductLanguageForm_<?php echo $row->language_code;?>,true);
}

/**
 * Init TinyMCE instances
 */
tinyMCE.init({
    theme: 'advanced',
    theme_advanced_toolbar_location: 'top',
    theme_advanced_toolbar_align: 'left',
    width: '440',
    height: '225',
    mode: 'exact',
    elements: 'product_content_description_<?php echo $row->language_code?>',
    content_css: '<?php echo $this->APP_STATIC_SERVER; ?>/skins/<?php echo $this->APP_TEMPLATE; ?>/<?php echo $this->APP_SKIN; ?>/default.css',
    relative_urls: false,
    remove_script_host: false,
    readonly: true
})
<?php else:?>

/**
 * Init TinyMCE instances
 */
tinyMCE.init({
    theme: 'advanced',
    theme_advanced_toolbar_location: 'top',
    theme_advanced_toolbar_align: 'left',
    width: '440',
    height: '225',
    mode: 'exact',
    elements: 'product_content_description_<?php echo $row->language_code?>',
    content_css: '<?php echo $this->APP_STATIC_SERVER; ?>/skins/<?php echo $this->APP_TEMPLATE; ?>/<?php echo $this->APP_SKIN; ?>/default.css',
    relative_urls: false,
    remove_script_host: false    
})
<?php endif;?>

$(document).ready(function() {
    /*$("#edit_content_<?php echo $row->language_code;?>").click(function(){
        thischeck = $(this);
        if(thischeck.is (':checked')){
            disableEnableForm(document.addProductLanguageForm_<?php echo $row->language_code;?>,false);
        }else{
            disableEnableForm(document.addProductLanguageForm_<?php echo $row->language_code;?>,true);
        }
    })*/
});
</script>
<?php endif;?>
<?php endforeach;?>

<?php if ($this->allow('choose-attribute')):?>
<span id="choice3" <?php if($product->product_bundle == 1){?>style="display: none;"<?php }?>>
    <div>&nbsp;</div>
    <div>&nbsp;</div>
    <div class="grid_12 t_a_bottom" style="font-size:13px; font-weight:bold">3. <?php echo $this->translator('product_choose_attribute_guide'); ?></div>
    <div class="grid_12"><hr></hr></div>
    <div class="clearfix t_a_bottom">
        <label>&nbsp;</label>
        <a class="t_a_ui_button_link" href="<?php echo $this->url(array('product_id' => $product->product_id), 'shop_product_choose_attribute'); ?>"><span><?php echo $this->translator('product_choose_attribute'); ?></span></a>
    </div>
</span>
<?php endif;?>

<span id="choice4" <?php if($product->product_bundle == 1){?>style="display: none;"<?php }?>>
<?php if ($this->allow('production-duration')):?>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div class="grid_12 t_a_bottom" style="font-size:13px; font-weight:bold">4. <?php echo $this->translator('product_choose_production_duration'); ?></div>
<div class="grid_12"><hr></hr></div>
<form method="post" action="<?php echo $this->url(array('product_id' => $this->product->product_id), 'shop_product_duration'); ?>" id="addProductionDuration">
    <div class="grid_12 t_a_bottom">
        <div class="prefix_1 suffix_1">
            <div class="clearfix t_a_bottom">
                <label><?php echo $this->translator('product_choose_production_duration'); ?>:</label>
                <input type="text" value="<?php echo $product->production_duration;?>" name="production_duration"> <?php echo $this->translator('production_duration_date'); ?>
            </div>
            <div class="clearfix t_a_bottom">
                <label>&nbsp;</label>
                <button type="submit"><span><?php echo $this->translator('product_add_save_button'); ?></span></button>
            </div>
        </div>
    </div>
</form>
<?php endif;?>
<?php endif;?>
</span>
<script type="text/javascript">
function insertImage(url) {	
    num_image = jQuery('#hd_num_image').val();
    if(num_image >= 7){
        alert('<?php echo $this->translator('product_upload_full_image');?>');
    }else{
        htmlVal = document.getElementById('viewIMG').innerHTML;
        new_str_image = '<span class="box_image" id="'+num_image+'"><a href="javascript:void(0)" class="removeImage" onClick="removeImage(this);" rel="'+num_image+'" val="'+url+'">[x]</a><img src="'+url+'" width="150"/></span>'+htmlVal;
        document.getElementById('viewIMG').innerHTML = new_str_image;

        val = document.getElementById('product_image').value;
        document.getElementById('product_image').value = url+','+val;

        /**
        * Update num image
        */
        jQuery('#hd_num_image').attr('value', parseInt(num_image)+1);
    }
};
function implode( glue, pieces ) {  
     // Joins array elements placing glue string between items and return one string    
     //   
     // version: 812.316  
     // discuss at: http://phpjs.org/functions/implode  
     // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)  
     // +   improved by: Waldo Malqui Silva  
     // *     example 1: implode(' ', ['Kevin', 'van', 'Zonneveld']);  
     // *     returns 1: 'Kevin van Zonneveld'  
     return ( ( pieces instanceof Array ) ? pieces.join ( glue ) : pieces );  
}  
function removeImage(your) {
	
    rel = jQuery(your).attr('rel');
    //jQuery('#'+rel).html('');
    //jQuery('#'+rel).remove();
	$(your).parent("span").remove();

	var arr = [];	
	$("#viewIMG").find("img").each(function(){
		arr.push($(this).attr("src"));
	});
	var new_str_image = implode(',',arr);
	/*
    str_image = jQuery('#product_image').val();
    val = jQuery(your).attr('val');
    new_str_image = str_image.replace(val+',','');
	*/
    jQuery('#product_image').attr('value',new_str_image);

    /**
    * Update num image
    */
    num_image = jQuery('#hd_num_image').val();
    jQuery('#hd_num_image').attr('value', parseInt(num_image)-1);
};

function ajaxListBundle(productBundle){
    $.ajax({
        url: "<?php echo $this->url(array(), 'shop_product_list_bundle'); ?>",
        method : "POST",
        data: {value : productBundle, product_product_id_chain : '<?php echo $product->product_product_id_chain;?>','product_id':'<?php echo $this->product->product_id;?>'},
        success: function(html){
            $('#html_products').html(html);
        }
    });
}

$(document).ready(function() {
    <?php if($product->product_bundle == 1):?>
        var productBundle = '<?php echo $product->product_bundle;?>';
        ajaxListBundle(productBundle);
    <?php endif;?>

    /**
    * Show multi image
    */
    var url = '<?php echo strip_tags($product->product_image);?>';
    <?php if($product->product_image):?>
        <?php
            $arrImages = explode(',', $product->product_image);
            //unset($arrImages[count($arrImages)-1]);
            $strUrl = '';
        ?>
        <?php $i_i = 1;foreach($arrImages as $image):?>
            <?php
				if(!empty($image))
					$strUrl .= "<span class=\"box_image\" id=\"{$i_i}\"><a href=\"javascript:void(0)\" class=\"removeImage\" onClick=\"removeImage(this);\" rel=\"{$i_i}\" val=\"{$image}\">[x]</a><img src=\"{$image}\" width=\"150\" /></span>";
            ?>
        <?php endforeach;?>
        jQuery('#hd_num_image').attr('value', '<?php echo count($arrImages)+1;?>');
        document.getElementById('viewIMG').innerHTML = '<?php echo $strUrl;?>';
    <?php endif;?>

    $('.product_bundle').click(function(){
        $('.product_bundle:checked').each(function(){
            if ($(this).val()== '1')
            {
                $('#html_products').html('Loading...');
                var productBundle = $(this).val();
                ajaxListBundle(productBundle);
				/*
                $.ajaxq('product',{
                    url: "<?php echo $this->url(array(), 'shop_product_list_bundle'); ?>",
                    method : "POST",
                    data: {value : $(this).val(), product_product_id_chain : ','},
                    success: function(html){
                        $('#html_products').html(html);
                    }
                });
				*/
                $('#choice3').hide();
                $('#choice4').hide();
            }
            else if ($(this).val()== '0')
            {
                $('#html_products').html('Please! Click to choice radio button...');
                $('#choice3').show();
                $('#choice4').show();
            }
            else
            {
                alert('789');
            }
        });
    });

    $('#editProductForm').validate({
        rules: {
            product_admin_name: {
                required: true,
                maxlength: 255
            },
            product_status:{
                required: true,
            },
            product_status_of_delivery:{
                required: true
            },
            product_quantity_mode:{
                required: true
            },
            product_quantity:{
                required: true,
                number:true
            },
            product_price:{
                number: true
            },
            "category_id[]": "required",
            product_shipping_price:{
                number:true
            },
            product_shipping_price_1:{
                number:true
            },
            product_shipping_price_2:{
                number:true
            }
        },
        messages: {
            product_admin_name: {
                required: "<?php echo $this->translator('product_name_required'); ?>",
                maxlength: "<?php echo $this->translator('product_name_maxlength'); ?>"
            },
            product_status: "<?php echo $this->translator('product_status_required'); ?>",
            product_status_of_delivery: "<?php echo $this->translator('product_status_of_delivery_required'); ?>",
            product_quantity_mode: "<?php echo $this->translator('product_quantity_mode_required'); ?>",
            product_quantity: {
                required: "<?php echo $this->translator('product_quantity_required'); ?>",
                number: "<?php echo $this->translator('product_quantity_invalid_number'); ?>"
            },
            product_price: "<?php echo $this->translator('product_price_number'); ?>",
            "category_id[]": "<?php echo $this->translator('product_category_id_required'); ?>",
            product_shipping_price:'<?php echo $this->translator('product_shipping_price_1_invalid_number'); ?>',
            product_shipping_price_1:'<?php echo $this->translator('product_shipping_price_1_invalid_number'); ?>',
            product_shipping_price_2:'<?php echo $this->translator('product_shipping_price_1_invalid_number'); ?>'
        }
    });


    $.validator.addMethod('slug', function(value) {
        value = value.replace(/^\s+|\s+$/g, '');
        var regex = new RegExp(/^[a-z0-9\-]+$/);
        if (value == '' || value.match(regex)) {
            return true;
        } else {
            return false;
        }
    });
    <?php foreach ($this->languages as $row):?>

        $('#addProductLanguageForm_<?php echo $row->language_code;?>').validate({
        rules: {
            product_content_name: {
                required: true,
                maxlength: 255
            },
            product_content_friendly_url: {
                slug: true,
                maxlength: 255
            }
        },
        messages: {
            product_content_name: {
                required: "<?php echo $this->translator('product_content_name_required'); ?>",
                maxlength: "<?php echo $this->translator('product_content_name_maxlength'); ?>"
            },
            product_content_friendly_url: {
                slug: "<?php echo $this->translator('product_content_friendly_url_validate'); ?>",
                maxlength: "<?php echo $this->translator('product_content_friendly_url_maxlength'); ?>"
            }
        }
    });
    <?php endforeach;?>

    <?php foreach ($this->languages as $row):?>
        $('#addProductLanguageForm_<?php echo $row->language_code;?> #product_content_name').bind('change', function() {
            $('#addProductLanguageForm_<?php echo $row->language_code;?> #product_content_friendly_url').val(normalizeSlug($(this).val()));
        });
    <?php endforeach;?>
    $('#product_status_of_delivery').bind('change', function(){
        var value = $(this).val();
        if(value == 'deliver_able'){
            $('#product_quantity_mode').removeAttr('disabled');
            $('#product_quantity_mode').attr('value', '');

            $('#product_quantity_mode').bind('change', function(){
                var value_mode = $('#product_quantity_mode').val();
                if(value_mode == "infinity"){
                    $('#product_quantity').attr('disabled', 'disabled');
                    $('#product_quantity').attr('value', '');
                }
                else if(value_mode == "amount"){
                    $('#product_quantity').attr('disabled', '');
                    $('#product_quantity').attr('value', '');
                }
                else{
                    $('#product_quantity').attr('disabled', 'disabled');
                    $('#product_quantity').attr('value', '');
                }
            });
        }
        else if(value == 'non_deliver_able'){
            $('#product_quantity_mode').attr('disabled', 'disabled');
            $('#product_quantity_mode').attr('value', '');
            $('#product_quantity').attr('disabled', 'disabled');
            $('#product_quantity').attr('value', '');
        }
        else if(value == 'please_contact'){			
            $('#product_quantity_mode').attr('disabled', 'disabled');
            $('#product_quantity_mode').attr('value', '');
            $('#product_quantity').attr('disabled', 'disabled');
            $('#product_quantity').attr('value', '');
        }
        else{
            $('#product_quantity_mode').attr('disabled', 'disabled');
            $('#product_quantity_mode').attr('value', '');
            $('#product_quantity').attr('disabled', 'disabled');
            $('#product_quantity').attr('value', '');
        }
    });
    $('#product_quantity_mode').bind('change', function(){
        var product_status_of_delivery = $('#product_status_of_delivery').val();
        if(product_status_of_delivery == 'deliver_able'){
            var value_mode = $('#product_quantity_mode').val();
            if(value_mode == "infinity"){
                $('#product_quantity').attr('disabled', 'disabled');
                $('#product_quantity').attr('value', '');
            }
            else if(value_mode == "amount"){
                $('#product_quantity').attr('disabled', '');
                $('#product_quantity').attr('value', '');
            }
            else{
                $('#product_quantity').attr('disabled', 'disabled');
                $('#product_quantity').attr('value', '');
            }
        }
    });
});

function disableEnableForm(xForm,xHow){
  objElems = xForm.elements;
  for(i=0;i<objElems.length;i++){
    if(objElems[i].type != 'checkbox'){
        objElems[i].disabled = xHow;
    }
  }
  //tinymce.get('product_content_description_en_US').getDoc().designMode = 'Off';   
  tinyMCE.init({mode : "none", readonly : true});
}

function normalizeSlug(str) {
    str = str.replace(/^\s+|\s+$/g, '');
    var from = "ÁÀẠẢÃĂẮẰẶẲẴÂẤẦẬẨẪáàạảãăắằặẳẵâấầậẩẫóòọỏõÓÒỌỎÕôốồộổỗÔỐỒỘỔỖơớờợởỡƠỚỜỢỞỠéèẹẻẽÉÈẸẺẼêếềệểễÊẾỀỆỂỄúùụủũÚÙỤỦŨưứừựửữƯỨỪỰỬỮíìịỉĩÍÌỊỈĨýỳỵỷỹÝỲỴỶỸĐđÑñÇç·/_,:;";
    var to   = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaooooooooooooooooooooooooooooooooooeeeeeeeeeeeeeeeeeeeeeeuuuuuuuuuuuuuuuuuuuuuuiiiiiiiiiiyyyyyyyyyyddnncc------";

    for (var i = 0, l = from.length ; i < l; i++) {
        str = str.replace(new RegExp(from[i], "g"), to[i]);
    }
    str = str.replace(/[^a-zA-Z0-9 -]/g, '').replace(/\s+/g, '-').toLowerCase();
    return str;
};
</script>
